using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using JGSY.CMS.LowCode.Platform.Infrastructure;

namespace JGSY.CMS.LowCode.Platform.Infrastructure.Configuration.ServiceModules.Modules
{
    /// <summary>
    /// 缓存服务模块
    /// 包含内存缓存、分布式缓存（Redis、Memcached等）配置
    /// </summary>
    public class CacheModule : IServiceModule
    {
        public string ModuleName => "缓存服务";
        public int Priority => 4;
        public bool LoadInFastMode => true; // 快速模式需要基本缓存
        public ModulePermission RequiredPermission => ModulePermission.CacheServices;
        public bool IsCriticalModule => false; // 非关键模块

        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            // 添加缓存服务 - 完整功能
            services.AddCacheExtensions(configuration);
            services.AddMemoryCache();
            services.AddDistributedMemoryCache();
        }

        public void ConfigureMinimalServices(IServiceCollection services, IConfiguration configuration)
        {
            // 精简缓存功能 - 只配置内存缓存
            services.AddMemoryCache();
            services.AddDistributedMemoryCache();
        }

        public bool ValidateConfiguration(IConfiguration configuration)
        {
            // 缓存服务可以使用默认配置，始终有效
            return true;
        }
    }
}
